<?php
if (isset($_REQUEST["sendnewcat"]))
{
	$success = true;
	$validator = array("name" => "isPosted",
						"parentid" => "isPosted",
						"color" => "isColor",
						"direction" => "isPosted",
						"type" => "isPosted",
						"amount" => "isInteger");

	if (validateForm($validator, $_REQUEST) && ($newCategoryId = setNewCategory($_REQUEST["name"], $_REQUEST["description"], $_REQUEST["parentid"], $_REQUEST["color"], $_REQUEST["direction"])))
	{
		if (isset($_REQUEST["type"]) && ($_REQUEST["type"] != "nobudget"))
		{
			if (!setBudget($_SESSION["userid"], $newCategoryId, $_REQUEST["type"], $_REQUEST["amount"]))
			{
				$success = false;
			}
		}
	}
	else
	{
		$success = false;
	}
}

$categoryTree = getCategoryTree("NULL", 0, false);
?>
			<div id="textcontainer">
				<h2>Új kategória</h2>
				<p>
					<?php if (isset($success) && !$success) print "<div class=\"errortitle\">valami nem sikerult!</div>";?>
					<form name="newcategory" action="<?php print $_SERVER["SCRIPT_NAME"] . "?" . $_SERVER["QUERY_STRING"];?>" method="post">
						név: <input type="text" name="name"<?php print (isset($_REQUEST["name"]) && !$success)?' value="' . $_REQUEST["name"] . '"':"";?>/><br/>
						leírás: <textarea name="description"><?php print (isset($_REQUEST["description"]) && !$success)?$_REQUEST["description"]:"";?></textarea><br/>
						kategória: <select name="parentid">
						<option value="NULL"<?php print (isset($_REQUEST["parentid"]) && !$success && ($_REQUEST["parentid"] == "NULL"))?' selected="selected"':"";?>>főkategória</option>
<?php
	foreach ($categoryTree as $category)
	{
		print "<option value=\"" . $category["category"]["id"] . "\"" . (isset($_REQUEST["parentid"]) && !$success && ($_REQUEST["parentid"] == $category["category"]["id"])?" selected=\"selected\"":"") . ">" . $category["category"]["name"] . "</option>";
	}
?>
						</select><br/>
						szín: <input type="text" name="color"<?php print (isset($_REQUEST["color"]) && !$success)?' value="' . $_REQUEST["color"] . '"':"";?>/><br/>
						típus: <select name="direction">
						<option value="E"<?php print (isset($_REQUEST["direction"]) && !$success && ($_REQUEST["direction"] == "E"))?' selected="selected"':"";?>>kiadás</option>
						<option value="I"<?php print (isset($_REQUEST["direction"]) && !$success && ($_REQUEST["direction"] == "I"))?' selected="selected"':"";?>>bevétel</option>
						<option value="B"<?php print (isset($_REQUEST["direction"]) && !$success && ($_REQUEST["direction"] == "B"))?' selected="selected"':"";?>>mindkettő</option>
						</select><br/>
						büdzsé: <select name="type">
						<option value="nobudget"<?php print (isset($_REQUEST["type"]) && !$success && ($_REQUEST["type"] == "nobudget"))?' selected="selected"':"";?>>- nincs-</option>
						<option value="M"<?php print (isset($_REQUEST["type"]) && !$success && ($_REQUEST["type"] == "M"))?' selected="selected"':"";?>>havi</option>
						<option value="Y"<?php print (isset($_REQUEST["type"]) && !$success && ($_REQUEST["type"] == "Y"))?' selected="selected"':"";?>>éves</option>
						<option value="H"<?php print (isset($_REQUEST["type"]) && !$success && ($_REQUEST["type"] == "H"))?' selected="selected"':"";?>>féléves</option>
						<option value="Q"<?php print (isset($_REQUEST["type"]) && !$success && ($_REQUEST["type"] == "Q"))?' selected="selected"':"";?>>negyedéves</option>
						<option value="W"<?php print (isset($_REQUEST["type"]) && !$success && ($_REQUEST["type"] == "W"))?' selected="selected"':"";?>>heti</option>
						</select><br/>
						összeg: <input type="text" name="amount"<?php print (isset($_REQUEST["amount"]) && !$success)?' value="' . $_REQUEST["amount"] . '"':"";?>/><br/>
						<input type="submit" name="sendnewcat" value="Ment"/>
					</form>
				</p>
			</div>
			<!---->
